package com.kfm.exec;

import java.util.*;

public class Student {

    private int id;
    private int score;

    public Student() {
        // id (1-40)之间

        // nextInt(n) + 1 [0, n) --> [1, n + 1)
        this.id = new Random().nextInt(40) + 1;
        this.score = new Random().nextInt(101);
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", score=" + score +
                '}';
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }
}

class StudentTest {
    public static void main(String[] args) {
        // LinkedList list = new LinkedList<>();
        TreeSet set = new TreeSet(new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                return ((Student)o1).getScore() - ((Student)o2).getScore();
            }
        });
        for (int i = 0; i < 20; i++) {
            Student stu = new Student();
            set.add(stu);
        }
        System.out.println(set.first());
        System.out.println(set.last());
        // System.out.println(list);
        // Collections.sort(list, new Comparator<Object>() {
        //     @Override
        //     public int compare(Object o1, Object o2) {
        //         return ((Student) o1).getScore() - ((Student) o2).getScore();
        //     }
        // });
        // System.out.println(list.getFirst());
        // System.out.println(list.getLast());
        // list.forEach(System.out::println);
    }
}
